package com.aptech.forms.dqthanh;

import com.aptech.beans.Customer;
import com.aptech.dao.CustomerManager;
import com.aptech.validate.CustomerValidator;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import javax.swing.RowFilter;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableRowSorter;

public class CustommerList extends javax.swing.JFrame {

    private Customer objCustomer;
   

    public CustommerList() {
        initComponents();
        setLocationRelativeTo(null);
        loadData();
        // jtfCustomerList_Id.setEditable(false);

    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jdCustomerList_Insert = new javax.swing.JDialog();
        jPanel1 = new javax.swing.JPanel();
        lb_name = new javax.swing.JLabel();
        jtfCustomerList_CustomerName = new javax.swing.JTextField();
        lb_email = new javax.swing.JLabel();
        jtfCustomerList_CustomerEmail = new javax.swing.JTextField();
        lb_address = new javax.swing.JLabel();
        jtfCustomerList_CustomerPhone = new javax.swing.JTextField();
        lb_phone = new javax.swing.JLabel();
        jtfCustomerList_CustomerAddress = new javax.swing.JTextField();
        jcbCustomerList_RelationCustomer = new javax.swing.JCheckBox();
        lb_checkEmail = new javax.swing.JLabel();
        lb_checkAddress = new javax.swing.JLabel();
        lb_checkPhone = new javax.swing.JLabel();
        lb_checkName = new javax.swing.JLabel();
        jtfCustomerList_Reset = new javax.swing.JButton();
        jtfCustomerList_Submit = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();
        jdCustomerList_Update = new javax.swing.JDialog();
        jPanel2 = new javax.swing.JPanel();
        jcbCustomerList_Id = new javax.swing.JLabel();
        jtfCustomerList_UpId = new javax.swing.JTextField();
        jcbCustomerList_UpName = new javax.swing.JLabel();
        jtfCustomerList_UpCustomerName = new javax.swing.JTextField();
        jcbCustomerList_UpEmail = new javax.swing.JLabel();
        jtfCustomerList_UpCustomerEmail = new javax.swing.JTextField();
        jcbCustomerList_UpAddress = new javax.swing.JLabel();
        jtfCustomerList_UpCustomerPhone = new javax.swing.JTextField();
        jcbCustomerList_UpPhone = new javax.swing.JLabel();
        jtfCustomerList_UpCustomerAddress = new javax.swing.JTextField();
        lb_UpcheckName = new javax.swing.JLabel();
        lb_UpcheckEmail = new javax.swing.JLabel();
        lb_UpcheckAddress = new javax.swing.JLabel();
        lb_UpcheckPhone = new javax.swing.JLabel();
        jcbCustomerList_UpRelationCustomer = new javax.swing.JCheckBox();
        jtfCustomerList_Reset1 = new javax.swing.JButton();
        jtfCustomerList_Submit1 = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        jtfCustomerList_Cancel = new javax.swing.JButton();
        jdCustomerList_Notification = new javax.swing.JDialog();
        jLabel5 = new javax.swing.JLabel();
        lb_Email = new javax.swing.JLabel();
        lb_Phones = new javax.swing.JLabel();
        lb_Address = new javax.swing.JLabel();
        lb_Name = new javax.swing.JLabel();
        jlblStatus_Name = new javax.swing.JLabel();
        jlblStatus_Address = new javax.swing.JLabel();
        jlblStatus_Email = new javax.swing.JLabel();
        jlblStatus_Phone = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtbCustomertList = new javax.swing.JTable();
        jbtCustomerListInsert = new javax.swing.JButton();
        jbtCustomerListUpdate = new javax.swing.JButton();
        jbtCustomerListDelete = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jlblAccList_Username1 = new javax.swing.JLabel();
        jtfCus_Search = new javax.swing.JTextField();

        jdCustomerList_Insert.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        jdCustomerList_Insert.setTitle("Customer Manager");
        jdCustomerList_Insert.setResizable(false);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Customer Information ", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Segoe UI Light", 1, 14), new java.awt.Color(255, 0, 0))); // NOI18N

        lb_name.setFont(new java.awt.Font("Segoe UI Light", 1, 14)); // NOI18N
        lb_name.setForeground(new java.awt.Color(51, 0, 255));
        lb_name.setText("Customer Name");

        jtfCustomerList_CustomerName.setFont(new java.awt.Font("Segoe UI Light", 1, 14)); // NOI18N

        lb_email.setFont(new java.awt.Font("Segoe UI Light", 1, 14)); // NOI18N
        lb_email.setForeground(new java.awt.Color(51, 0, 255));
        lb_email.setText("Customer Email");

        jtfCustomerList_CustomerEmail.setFont(new java.awt.Font("Segoe UI Light", 1, 14)); // NOI18N

        lb_address.setFont(new java.awt.Font("Segoe UI Light", 1, 14)); // NOI18N
        lb_address.setForeground(new java.awt.Color(51, 0, 255));
        lb_address.setText("Customer Address");

        jtfCustomerList_CustomerPhone.setFont(new java.awt.Font("Segoe UI Light", 1, 14)); // NOI18N

        lb_phone.setFont(new java.awt.Font("Segoe UI Light", 1, 14)); // NOI18N
        lb_phone.setForeground(new java.awt.Color(51, 0, 255));
        lb_phone.setText("Customer Phone");

        jtfCustomerList_CustomerAddress.setFont(new java.awt.Font("Segoe UI Light", 1, 14)); // NOI18N

        jcbCustomerList_RelationCustomer.setFont(new java.awt.Font("Segoe UI Light", 1, 14)); // NOI18N
        jcbCustomerList_RelationCustomer.setForeground(new java.awt.Color(255, 0, 51));
        jcbCustomerList_RelationCustomer.setText("Is Relation Customer");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(26, 26, 26)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(lb_address)
                    .addComponent(lb_email, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lb_phone, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lb_name, javax.swing.GroupLayout.Alignment.LEADING))
                .addGap(42, 42, 42)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jcbCustomerList_RelationCustomer)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jtfCustomerList_CustomerPhone, javax.swing.GroupLayout.DEFAULT_SIZE, 186, Short.MAX_VALUE)
                            .addComponent(jtfCustomerList_CustomerEmail, javax.swing.GroupLayout.DEFAULT_SIZE, 186, Short.MAX_VALUE)
                            .addComponent(jtfCustomerList_CustomerName)
                            .addComponent(jtfCustomerList_CustomerAddress))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lb_checkEmail)
                            .addComponent(lb_checkAddress)
                            .addComponent(lb_checkPhone)
                            .addComponent(lb_checkName, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(49, 49, 49)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lb_name)
                    .addComponent(jtfCustomerList_CustomerName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lb_checkName))
                .addGap(27, 27, 27)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(lb_email)
                        .addComponent(jtfCustomerList_CustomerEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(lb_checkEmail))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(lb_address)
                        .addComponent(jtfCustomerList_CustomerAddress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(lb_checkAddress))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(lb_phone)
                        .addComponent(jtfCustomerList_CustomerPhone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(lb_checkPhone))
                .addGap(18, 18, 18)
                .addComponent(jcbCustomerList_RelationCustomer)
                .addContainerGap(40, Short.MAX_VALUE))
        );

        jtfCustomerList_Reset.setFont(new java.awt.Font("Segoe UI Light", 1, 14)); // NOI18N
        jtfCustomerList_Reset.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/image/016.png"))); // NOI18N
        jtfCustomerList_Reset.setText("Reset");
        jtfCustomerList_Reset.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtfCustomerList_ResetActionPerformed(evt);
            }
        });

        jtfCustomerList_Submit.setFont(new java.awt.Font("Segoe UI Light", 1, 14)); // NOI18N
        jtfCustomerList_Submit.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/image/003.png"))); // NOI18N
        jtfCustomerList_Submit.setText("Submit");
        jtfCustomerList_Submit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtfCustomerList_SubmitActionPerformed(evt);
            }
        });

        jLabel4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/image/029.png"))); // NOI18N

        javax.swing.GroupLayout jdCustomerList_InsertLayout = new javax.swing.GroupLayout(jdCustomerList_Insert.getContentPane());
        jdCustomerList_Insert.getContentPane().setLayout(jdCustomerList_InsertLayout);
        jdCustomerList_InsertLayout.setHorizontalGroup(
            jdCustomerList_InsertLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jdCustomerList_InsertLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(jdCustomerList_InsertLayout.createSequentialGroup()
                .addGroup(jdCustomerList_InsertLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jdCustomerList_InsertLayout.createSequentialGroup()
                        .addGap(72, 72, 72)
                        .addComponent(jtfCustomerList_Submit)
                        .addGap(47, 47, 47)
                        .addComponent(jtfCustomerList_Reset, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jdCustomerList_InsertLayout.createSequentialGroup()
                        .addGap(181, 181, 181)
                        .addComponent(jLabel4)))
                .addGap(0, 84, Short.MAX_VALUE))
        );
        jdCustomerList_InsertLayout.setVerticalGroup(
            jdCustomerList_InsertLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jdCustomerList_InsertLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(jdCustomerList_InsertLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtfCustomerList_Submit, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jtfCustomerList_Reset, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );

        jdCustomerList_Update.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        jdCustomerList_Update.setTitle("Customer Manager");
        jdCustomerList_Update.setResizable(false);

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Customer Information ", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Segoe UI Light", 1, 14), new java.awt.Color(255, 0, 0))); // NOI18N

        jcbCustomerList_Id.setFont(new java.awt.Font("Segoe UI Light", 1, 14)); // NOI18N
        jcbCustomerList_Id.setForeground(new java.awt.Color(51, 0, 255));
        jcbCustomerList_Id.setText("Customer ID");

        jtfCustomerList_UpId.setFont(new java.awt.Font("Segoe UI Light", 1, 14)); // NOI18N

        jcbCustomerList_UpName.setFont(new java.awt.Font("Segoe UI Light", 1, 14)); // NOI18N
        jcbCustomerList_UpName.setForeground(new java.awt.Color(51, 0, 255));
        jcbCustomerList_UpName.setText("Customer Name");

        jtfCustomerList_UpCustomerName.setFont(new java.awt.Font("Segoe UI Light", 1, 14)); // NOI18N

        jcbCustomerList_UpEmail.setFont(new java.awt.Font("Segoe UI Light", 1, 14)); // NOI18N
        jcbCustomerList_UpEmail.setForeground(new java.awt.Color(51, 0, 255));
        jcbCustomerList_UpEmail.setText("Customer Email");

        jtfCustomerList_UpCustomerEmail.setFont(new java.awt.Font("Segoe UI Light", 1, 14)); // NOI18N

        jcbCustomerList_UpAddress.setFont(new java.awt.Font("Segoe UI Light", 1, 14)); // NOI18N
        jcbCustomerList_UpAddress.setForeground(new java.awt.Color(51, 0, 255));
        jcbCustomerList_UpAddress.setText("Customer Address");

        jtfCustomerList_UpCustomerPhone.setFont(new java.awt.Font("Segoe UI Light", 1, 14)); // NOI18N

        jcbCustomerList_UpPhone.setFont(new java.awt.Font("Segoe UI Light", 1, 14)); // NOI18N
        jcbCustomerList_UpPhone.setForeground(new java.awt.Color(51, 0, 255));
        jcbCustomerList_UpPhone.setText("Customer Phone");

        jtfCustomerList_UpCustomerAddress.setFont(new java.awt.Font("Segoe UI Light", 1, 14)); // NOI18N

        jcbCustomerList_UpRelationCustomer.setFont(new java.awt.Font("Segoe UI Light", 1, 14)); // NOI18N
        jcbCustomerList_UpRelationCustomer.setForeground(new java.awt.Color(255, 0, 51));
        jcbCustomerList_UpRelationCustomer.setText("Is Relation Customer");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(26, 26, 26)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jcbCustomerList_UpAddress)
                    .addComponent(jcbCustomerList_Id, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jcbCustomerList_UpEmail, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jcbCustomerList_UpPhone, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jcbCustomerList_UpName, javax.swing.GroupLayout.Alignment.LEADING))
                .addGap(42, 42, 42)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jcbCustomerList_UpRelationCustomer)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jtfCustomerList_UpCustomerPhone, javax.swing.GroupLayout.DEFAULT_SIZE, 186, Short.MAX_VALUE)
                            .addComponent(jtfCustomerList_UpId)
                            .addComponent(jtfCustomerList_UpCustomerEmail, javax.swing.GroupLayout.DEFAULT_SIZE, 186, Short.MAX_VALUE)
                            .addComponent(jtfCustomerList_UpCustomerName)
                            .addComponent(jtfCustomerList_UpCustomerAddress))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(lb_UpcheckEmail, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(lb_UpcheckAddress, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(lb_UpcheckPhone, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(lb_UpcheckName, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addContainerGap(15, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jcbCustomerList_Id)
                    .addComponent(jtfCustomerList_UpId, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jcbCustomerList_UpName)
                            .addComponent(jtfCustomerList_UpCustomerName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(17, 17, 17)
                        .addComponent(lb_UpcheckName)))
                .addGap(27, 27, 27)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jcbCustomerList_UpEmail)
                        .addComponent(jtfCustomerList_UpCustomerEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(lb_UpcheckEmail))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jcbCustomerList_UpAddress)
                        .addComponent(jtfCustomerList_UpCustomerAddress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(lb_UpcheckAddress))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jcbCustomerList_UpPhone)
                        .addComponent(jtfCustomerList_UpCustomerPhone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(lb_UpcheckPhone))
                .addGap(18, 18, 18)
                .addComponent(jcbCustomerList_UpRelationCustomer)
                .addContainerGap(40, Short.MAX_VALUE))
        );

        jtfCustomerList_Reset1.setFont(new java.awt.Font("Segoe UI Light", 1, 14)); // NOI18N
        jtfCustomerList_Reset1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/image/016.png"))); // NOI18N
        jtfCustomerList_Reset1.setText("Reset");
        jtfCustomerList_Reset1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtfCustomerList_Reset1ActionPerformed(evt);
            }
        });

        jtfCustomerList_Submit1.setFont(new java.awt.Font("Segoe UI Light", 1, 14)); // NOI18N
        jtfCustomerList_Submit1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/image/003.png"))); // NOI18N
        jtfCustomerList_Submit1.setText("Submit");
        jtfCustomerList_Submit1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtfCustomerList_Submit1ActionPerformed(evt);
            }
        });

        jLabel3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/image/029.png"))); // NOI18N

        jtfCustomerList_Cancel.setFont(new java.awt.Font("Segoe UI Light", 1, 14)); // NOI18N
        jtfCustomerList_Cancel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/image/005.png"))); // NOI18N
        jtfCustomerList_Cancel.setText("Cancel");
        jtfCustomerList_Cancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtfCustomerList_CancelActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jdCustomerList_UpdateLayout = new javax.swing.GroupLayout(jdCustomerList_Update.getContentPane());
        jdCustomerList_Update.getContentPane().setLayout(jdCustomerList_UpdateLayout);
        jdCustomerList_UpdateLayout.setHorizontalGroup(
            jdCustomerList_UpdateLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jdCustomerList_UpdateLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jdCustomerList_UpdateLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jdCustomerList_UpdateLayout.createSequentialGroup()
                        .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jdCustomerList_UpdateLayout.createSequentialGroup()
                        .addGap(0, 27, Short.MAX_VALUE)
                        .addComponent(jtfCustomerList_Submit1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jtfCustomerList_Reset1, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jtfCustomerList_Cancel, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(32, 32, 32))))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jdCustomerList_UpdateLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel3)
                .addGap(185, 185, 185))
        );
        jdCustomerList_UpdateLayout.setVerticalGroup(
            jdCustomerList_UpdateLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jdCustomerList_UpdateLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(28, 28, 28)
                .addGroup(jdCustomerList_UpdateLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtfCustomerList_Submit1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jtfCustomerList_Reset1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jtfCustomerList_Cancel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(54, 54, 54))
        );

        jdCustomerList_Notification.setTitle("Notification");

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jLabel5.setForeground(new java.awt.Color(153, 0, 153));
        jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/image/031.png"))); // NOI18N
        jLabel5.setText("Notification");
        jLabel5.setToolTipText("");

        lb_Email.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        lb_Email.setForeground(new java.awt.Color(255, 102, 102));
        lb_Email.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        lb_Email.setText("Email");

        lb_Phones.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        lb_Phones.setForeground(new java.awt.Color(255, 102, 102));
        lb_Phones.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        lb_Phones.setText("Phone");

        lb_Address.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        lb_Address.setForeground(new java.awt.Color(255, 102, 102));
        lb_Address.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        lb_Address.setText("Address");

        lb_Name.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        lb_Name.setForeground(new java.awt.Color(255, 102, 102));
        lb_Name.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        lb_Name.setText("Name");

        jlblStatus_Name.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jlblStatus_Name.setForeground(new java.awt.Color(102, 102, 102));
        jlblStatus_Name.setText("field");

        jlblStatus_Address.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jlblStatus_Address.setForeground(new java.awt.Color(102, 102, 102));
        jlblStatus_Address.setText("field");

        jlblStatus_Email.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jlblStatus_Email.setForeground(new java.awt.Color(102, 102, 102));
        jlblStatus_Email.setText("field");

        jlblStatus_Phone.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jlblStatus_Phone.setForeground(new java.awt.Color(102, 102, 102));
        jlblStatus_Phone.setText("field");

        javax.swing.GroupLayout jdCustomerList_NotificationLayout = new javax.swing.GroupLayout(jdCustomerList_Notification.getContentPane());
        jdCustomerList_Notification.getContentPane().setLayout(jdCustomerList_NotificationLayout);
        jdCustomerList_NotificationLayout.setHorizontalGroup(
            jdCustomerList_NotificationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jdCustomerList_NotificationLayout.createSequentialGroup()
                .addGap(71, 71, 71)
                .addComponent(jLabel5)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jdCustomerList_NotificationLayout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addGroup(jdCustomerList_NotificationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lb_Name, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lb_Email, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lb_Address, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(lb_Phones, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 169, Short.MAX_VALUE)
                .addGroup(jdCustomerList_NotificationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jlblStatus_Name)
                    .addComponent(jlblStatus_Address)
                    .addComponent(jlblStatus_Email)
                    .addComponent(jlblStatus_Phone))
                .addContainerGap())
        );
        jdCustomerList_NotificationLayout.setVerticalGroup(
            jdCustomerList_NotificationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jdCustomerList_NotificationLayout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addComponent(jLabel5)
                .addGap(61, 61, 61)
                .addGroup(jdCustomerList_NotificationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lb_Name, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jlblStatus_Name))
                .addGap(18, 18, 18)
                .addGroup(jdCustomerList_NotificationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lb_Email, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jlblStatus_Email))
                .addGap(18, 18, 18)
                .addGroup(jdCustomerList_NotificationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lb_Address, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jlblStatus_Address))
                .addGap(18, 18, 18)
                .addGroup(jdCustomerList_NotificationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lb_Phones, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jlblStatus_Phone))
                .addContainerGap(27, Short.MAX_VALUE))
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setIconImage(new ImageIcon(getClass().getResource("/com/image/icon.png")).getImage());
        setResizable(false);

        jtbCustomertList.setFont(new java.awt.Font("Segoe UI Light", 0, 14)); // NOI18N
        jtbCustomertList.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Customer ID", "CustomerName", "Customer Email", "Customer Address", "Customer Phone", "IsRelation Customer"
            }
        ));
        jtbCustomertList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jScrollPane1.setViewportView(jtbCustomertList);

        jbtCustomerListInsert.setFont(new java.awt.Font("Segoe UI Light", 1, 14)); // NOI18N
        jbtCustomerListInsert.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/image/026.png"))); // NOI18N
        jbtCustomerListInsert.setText("Insert");
        jbtCustomerListInsert.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtCustomerListInsertActionPerformed(evt);
            }
        });

        jbtCustomerListUpdate.setFont(new java.awt.Font("Segoe UI Light", 1, 14)); // NOI18N
        jbtCustomerListUpdate.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/image/027.png"))); // NOI18N
        jbtCustomerListUpdate.setText("Update");
        jbtCustomerListUpdate.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtCustomerListUpdateActionPerformed(evt);
            }
        });

        jbtCustomerListDelete.setFont(new java.awt.Font("Segoe UI Light", 1, 14)); // NOI18N
        jbtCustomerListDelete.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/image/028.png"))); // NOI18N
        jbtCustomerListDelete.setText("Delete");
        jbtCustomerListDelete.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtCustomerListDeleteActionPerformed(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Segoe UI Light", 1, 24)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(255, 0, 0));
        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/image/009.png"))); // NOI18N
        jLabel1.setText("Customer Management");

        jlblAccList_Username1.setFont(new java.awt.Font("Segoe UI Light", 1, 14)); // NOI18N
        jlblAccList_Username1.setForeground(new java.awt.Color(51, 0, 255));
        jlblAccList_Username1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/image/057.png"))); // NOI18N

        jtfCus_Search.setFont(new java.awt.Font("Segoe UI Light", 0, 14)); // NOI18N
        jtfCus_Search.setToolTipText("Search by Name");
        jtfCus_Search.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jtfCus_SearchKeyPressed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(149, 149, 149)
                                .addComponent(jbtCustomerListInsert)
                                .addGap(18, 18, 18)
                                .addComponent(jbtCustomerListUpdate)
                                .addGap(18, 18, 18)
                                .addComponent(jbtCustomerListDelete))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(169, 169, 169)
                                .addComponent(jLabel1)))
                        .addGap(0, 138, Short.MAX_VALUE))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 658, Short.MAX_VALUE))
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(jlblAccList_Username1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jtfCus_Search, javax.swing.GroupLayout.PREFERRED_SIZE, 307, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(29, 29, 29))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jtfCus_Search, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jlblAccList_Username1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 244, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jbtCustomerListInsert, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jbtCustomerListUpdate)
                        .addComponent(jbtCustomerListDelete)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /* Reset button */
    public void resetForm() {

        // jtfCustomerList_Id.setText(null);
        jtfCustomerList_CustomerName.setText(null);
        jtfCustomerList_CustomerEmail.setText(null);
        jtfCustomerList_CustomerAddress.setText(null);
        jtfCustomerList_CustomerPhone.setText(null);
        jcbCustomerList_RelationCustomer.setSelected(false);

    }
    private void jtfCustomerList_ResetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtfCustomerList_ResetActionPerformed
        resetForm();
    }//GEN-LAST:event_jtfCustomerList_ResetActionPerformed


    /* Submit button */
    private void loadData() {
        tableModel = (DefaultTableModel) jtbCustomertList.getModel();

        tableModel.setRowCount(0);
        try {
            ResultSet resultSet = CustomerManager.displayAllRows();

            while (resultSet.next()) {
                Vector vector = new Vector();

                vector.add(String.valueOf(resultSet.getInt(1)).trim());
                vector.add(resultSet.getString(2).trim());
                vector.add(resultSet.getString(3).trim());
                vector.add(resultSet.getString(4).trim());
                vector.add(resultSet.getString(5).trim());
                if (resultSet.getBoolean(6) == true) {
                    vector.add("Yes");
                } else {
                    vector.add("No");
                }

                //vector.add(rsRole.getInt(2));
                tableModel.addRow(vector);

            }
        } catch (SQLException ex) {
            System.out.println(ex.getMessage());
        }
    }

    public void AddCustomer() {

        int test = 0;

        Customer cus = new Customer();

        cus.setCustomerName(jtfCustomerList_CustomerName.getText().trim());
        cus.setCustomerEmail(jtfCustomerList_CustomerEmail.getText().trim());
        cus.setCustomerAddress(jtfCustomerList_CustomerAddress.getText().trim());
        cus.setCustomerPhone(jtfCustomerList_CustomerPhone.getText().trim());
        cus.setIsRelationCustomer(jcbCustomerList_RelationCustomer.isSelected());

        try {
            test = CustomerManager.insertCustomer(cus);
            if (test == 1) {
                JOptionPane.showMessageDialog(this, "Add new Customer successfully !", "Add new Customer", JOptionPane.INFORMATION_MESSAGE);

                this.loadData();
            } else {
                JOptionPane.showMessageDialog(this, "Add new Customer error", "Add new Customer", JOptionPane.ERROR_MESSAGE);
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    private void jtfCustomerList_SubmitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtfCustomerList_SubmitActionPerformed
        boolean checkName = CustomerValidator.checkName(jtfCustomerList_CustomerName.getText());
        boolean checkEmail = CustomerValidator.checkEmail(jtfCustomerList_CustomerEmail.getText());
        boolean checkAddres = CustomerValidator.checkAddress(jtfCustomerList_CustomerAddress.getText());
        boolean checkPhone = CustomerValidator.checkPhone(jtfCustomerList_CustomerPhone.getText());

        if (checkEmail && checkName
                && checkAddres && checkPhone) {
            jdCustomerList_Notification.dispose();
            //Thuc hien update
            this.AddCustomer();
        } else {
            jdCustomerList_Notification.setVisible(true);
            jdCustomerList_Notification.pack();

            ImageIcon correctIcon = new javax.swing.ImageIcon(getClass().getResource("/com/image/032.png"));
            ImageIcon falseIcon = new javax.swing.ImageIcon(getClass().getResource("/com/image/033.png"));

            jlblStatus_Name.setIcon(checkName ? correctIcon : falseIcon);
            jlblStatus_Email.setIcon(checkEmail ? correctIcon : falseIcon);
            jlblStatus_Address.setIcon(checkAddres ? correctIcon : falseIcon);
            jlblStatus_Phone.setIcon(checkPhone ? correctIcon : falseIcon);
        }

    }//GEN-LAST:event_jtfCustomerList_SubmitActionPerformed

    /* Insert data */
    private void jbtCustomerListInsertActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtCustomerListInsertActionPerformed
//        this.AddCustomer
        this.resetForm();
        jdCustomerList_Insert.setVisible(true);
        jdCustomerList_Insert.pack();
        jdCustomerList_Insert.setLocationRelativeTo(null);
    }//GEN-LAST:event_jbtCustomerListInsertActionPerformed

    /* Update data */
    public void UpdateCustomer() {

        int test = 0;

        Customer cus = new Customer();
        int customerId = Integer.parseInt(jtfCustomerList_UpId.getText().trim());
        cus.setCustomerID(customerId);

        cus.setCustomerName(jtfCustomerList_UpCustomerName.getText().trim());
        cus.setCustomerEmail(jtfCustomerList_UpCustomerEmail.getText().trim());
        cus.setCustomerAddress(jtfCustomerList_UpCustomerAddress.getText().trim());
        cus.setCustomerPhone(jtfCustomerList_UpCustomerPhone.getText().trim());
        cus.setIsRelationCustomer(jcbCustomerList_UpRelationCustomer.isSelected());

        try {
            test = CustomerManager.updateCustomer(cus);
            if (test == 1) {
                JOptionPane.showMessageDialog(this, " Update Customer successfully !", "Add new Customer", JOptionPane.INFORMATION_MESSAGE);

                this.loadData();
            } else {
                JOptionPane.showMessageDialog(this, " Update Customer error", "Add new Customer", JOptionPane.ERROR_MESSAGE);
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    private void jbtCustomerListUpdateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtCustomerListUpdateActionPerformed

        resetForm();
        if (jtbCustomertList.getSelectedRowCount() == 1) {
            jdCustomerList_Update.setVisible(true);
            jdCustomerList_Update.pack();
            jdCustomerList_Update.setLocationRelativeTo(null);

            try {
                ResultSet resultSet = CustomerManager.displayAllRows();
                resultSet.absolute(jtbCustomertList.getSelectedRow() + 1);
                jtfCustomerList_UpId.setText(String.valueOf(resultSet.getInt(1)).trim());
                jtfCustomerList_UpCustomerName.setText(resultSet.getString(2).trim());
                jtfCustomerList_UpCustomerEmail.setText(resultSet.getString(3).trim());
                jtfCustomerList_UpCustomerAddress.setText(resultSet.getString(4).trim());
                jtfCustomerList_UpCustomerPhone.setText(resultSet.getString(5).trim());
                jcbCustomerList_UpRelationCustomer.setSelected(resultSet.getBoolean(6));

            } catch (SQLException ex) {
                System.err.println(ex.getMessage());
            }
        } else {
            JOptionPane.showMessageDialog(null, "Please choose a record to update", "Message", JOptionPane.INFORMATION_MESSAGE);
        }
    }//GEN-LAST:event_jbtCustomerListUpdateActionPerformed
    /**
     * *********
     */
    /* Delete data */
    public void deleteCustomer() {
        if (jtbCustomertList.getSelectedRowCount() == 1) {
            int reply = JOptionPane.showConfirmDialog(null, "Do you want to delete this record!",
                    "Message", JOptionPane.YES_NO_OPTION);
            if (reply == JOptionPane.YES_OPTION) {
                try {
                    ResultSet resultSet = CustomerManager.displayAllRows();
                    resultSet.absolute(jtbCustomertList.getSelectedRow() + 1);
                    resultSet.deleteRow();
                    loadData();
                } catch (SQLException ex) {
                    System.out.println(ex.getMessage());
                }
            }
        }
    }
    private void jbtCustomerListDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtCustomerListDeleteActionPerformed
        this.deleteCustomer();
    }//GEN-LAST:event_jbtCustomerListDeleteActionPerformed
    public void resetForm1() {

        jtfCustomerList_UpCustomerName.setText(null);
        jtfCustomerList_UpCustomerEmail.setText(null);
        jtfCustomerList_UpCustomerAddress.setText(null);
        jtfCustomerList_UpCustomerPhone.setText(null);
        jcbCustomerList_UpRelationCustomer.setSelected(false);

    }
private void jtfCustomerList_Reset1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtfCustomerList_Reset1ActionPerformed
// TODO add your handling code here:
    jtfCustomerList_UpId.setEditable(false);
    this.resetForm1();


}//GEN-LAST:event_jtfCustomerList_Reset1ActionPerformed

private void jtfCustomerList_Submit1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtfCustomerList_Submit1ActionPerformed
// TODO add your handling code here:
    boolean checkName = CustomerValidator.checkName(jtfCustomerList_UpCustomerName.getText());
    boolean checkEmail = CustomerValidator.checkEmail(jtfCustomerList_UpCustomerEmail.getText());
    boolean checkAddres = CustomerValidator.checkAddress(jtfCustomerList_UpCustomerAddress.getText());
    boolean checkPhone = CustomerValidator.checkPhone(jtfCustomerList_UpCustomerPhone.getText());

    if (checkEmail && checkName
            && checkAddres && checkPhone) {
        jdCustomerList_Notification.dispose();
        //Thuc hien update
        this.UpdateCustomer();
    } else {
        jdCustomerList_Notification.setVisible(true);
        jdCustomerList_Notification.pack();

        ImageIcon correctIcon = new javax.swing.ImageIcon(getClass().getResource("/com/image/032.png"));
        ImageIcon falseIcon = new javax.swing.ImageIcon(getClass().getResource("/com/image/033.png"));

        jlblStatus_Name.setIcon(checkName ? correctIcon : falseIcon);
        jlblStatus_Email.setIcon(checkEmail ? correctIcon : falseIcon);
        jlblStatus_Address.setIcon(checkAddres ? correctIcon : falseIcon);
        jlblStatus_Phone.setIcon(checkPhone ? correctIcon : falseIcon);
    }


}//GEN-LAST:event_jtfCustomerList_Submit1ActionPerformed

    private void jtfCustomerList_CancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtfCustomerList_CancelActionPerformed
        // TODO add your handling code hereet
        jdCustomerList_Update.dispose();

    }//GEN-LAST:event_jtfCustomerList_CancelActionPerformed

    private void jtfCus_SearchKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtfCus_SearchKeyPressed
        jtfCus_Search.getDocument().addDocumentListener(
                new DocumentListener() {
                    @Override
                    public void changedUpdate(DocumentEvent e) {
                        newFilter();
                    }

                    @Override
                    public void insertUpdate(DocumentEvent e) {
                        newFilter();
                    }

                    @Override
                    public void removeUpdate(DocumentEvent e) {
                        newFilter();
                    }

                    private void newFilter() {
                        TableRowSorter sorter = new TableRowSorter<>(tableModel);
                        jtbCustomertList.setRowSorter(sorter);
                        // Fillter data by cloumn = 1
                        RowFilter<DefaultTableModel, Object> rowFilter = RowFilter.regexFilter(jtfCus_Search.getText(), 1);
                        sorter.setRowFilter(rowFilter);
                    }
                });
    }//GEN-LAST:event_jtfCus_SearchKeyPressed

    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(CustommerList.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(CustommerList.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(CustommerList.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(CustommerList.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new CustommerList().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton jbtCustomerListDelete;
    private javax.swing.JButton jbtCustomerListInsert;
    private javax.swing.JButton jbtCustomerListUpdate;
    private javax.swing.JLabel jcbCustomerList_Id;
    private javax.swing.JCheckBox jcbCustomerList_RelationCustomer;
    private javax.swing.JLabel jcbCustomerList_UpAddress;
    private javax.swing.JLabel jcbCustomerList_UpEmail;
    private javax.swing.JLabel jcbCustomerList_UpName;
    private javax.swing.JLabel jcbCustomerList_UpPhone;
    private javax.swing.JCheckBox jcbCustomerList_UpRelationCustomer;
    private javax.swing.JDialog jdCustomerList_Insert;
    private javax.swing.JDialog jdCustomerList_Notification;
    private javax.swing.JDialog jdCustomerList_Update;
    private javax.swing.JLabel jlblAccList_Username1;
    private javax.swing.JLabel jlblStatus_Address;
    private javax.swing.JLabel jlblStatus_Email;
    private javax.swing.JLabel jlblStatus_Name;
    private javax.swing.JLabel jlblStatus_Phone;
    private javax.swing.JTable jtbCustomertList;
    private javax.swing.JTextField jtfCus_Search;
    private javax.swing.JButton jtfCustomerList_Cancel;
    private javax.swing.JTextField jtfCustomerList_CustomerAddress;
    private javax.swing.JTextField jtfCustomerList_CustomerEmail;
    private javax.swing.JTextField jtfCustomerList_CustomerName;
    private javax.swing.JTextField jtfCustomerList_CustomerPhone;
    private javax.swing.JButton jtfCustomerList_Reset;
    private javax.swing.JButton jtfCustomerList_Reset1;
    private javax.swing.JButton jtfCustomerList_Submit;
    private javax.swing.JButton jtfCustomerList_Submit1;
    private javax.swing.JTextField jtfCustomerList_UpCustomerAddress;
    private javax.swing.JTextField jtfCustomerList_UpCustomerEmail;
    private javax.swing.JTextField jtfCustomerList_UpCustomerName;
    private javax.swing.JTextField jtfCustomerList_UpCustomerPhone;
    private javax.swing.JTextField jtfCustomerList_UpId;
    private javax.swing.JLabel lb_Address;
    private javax.swing.JLabel lb_Email;
    private javax.swing.JLabel lb_Name;
    private javax.swing.JLabel lb_Phones;
    private javax.swing.JLabel lb_UpcheckAddress;
    private javax.swing.JLabel lb_UpcheckEmail;
    private javax.swing.JLabel lb_UpcheckName;
    private javax.swing.JLabel lb_UpcheckPhone;
    private javax.swing.JLabel lb_address;
    private javax.swing.JLabel lb_checkAddress;
    private javax.swing.JLabel lb_checkEmail;
    private javax.swing.JLabel lb_checkName;
    private javax.swing.JLabel lb_checkPhone;
    private javax.swing.JLabel lb_email;
    private javax.swing.JLabel lb_name;
    private javax.swing.JLabel lb_phone;
    // End of variables declaration//GEN-END:variables
 DefaultTableModel tableModel;
}
